<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    username <input type="text" id="input" />
    <script>
      const input = document.getElementById("input");

      input.onkeydown = function (e) {
        // keyCode 0-9
        // if (e.keyCode < 48 || e.keyCode > 57) {
        //   e.preventDefault();
        // }
        // key 0-9
        // if (e.key < "0" || e.key > "9") {
        //   e.preventDefault();
        // }
        // key a-f
        if (e.key < "a" || e.key > "f") {
          e.preventDefault();
        }
        // console.log(e.key, e.keyCode); // '0' 48->'9'-57
      };
    </script>
  </body>
</html>
